var rule = {
    title: '瓜子影视',
    host: 'https://haiwaiapi.1fc8ab0.com',
    url: 'https://haiwaiapi.1fc8ab0.com/Pc/Resource/ModuleInfo/ShowOnes#fyclass',
    detailUrl: 'https://haiwaiapi.1fc8ab0.com/Pc/Resource/GetVodInfo#fyid',
    searchUrl: 'https://haiwaiapi.1fc8ab0.com/Pc/Search/WordList#**',
    headers: {
        'User-Agent': 'Mozilla/5.0',
        'Content-Type': 'application/json'
    },
    timeout: 5000,
    class_name: '热门&电影&国产剧&动漫&综艺&短剧&海外剧&体育',
    class_url: '1&3&4&5&6&16&23656&15443',
    searchable: 1,
    quickSearch: 1,
    filterable: 0,
    play_parse: true,
    
    lazy: `js:
        input = { parse: 0, url: input };
    `,
    
    推荐: `js:
        let d = [];
        try {
            let reqBody = JSON.stringify({});
            let res = post(HOST + '/Pc/Resource/IndexShow/ShowOnes', {
                headers: {
                    'Content-Type': 'application/json'
                },
                body: reqBody
            });
            let json = JSON.parse(res);
            if (json.code === 200 && json.data && json.data.list) {
                json.data.list.forEach(module => {
                    if (module.list && Array.isArray(module.list)) {
                        module.list.forEach(it => {
                            d.push({
                                vod_id: it.vod_id + '',
                                vod_name: it.c_name || '',
                                vod_pic: it.c_pic || '',
                                vod_remarks: it.vod_continu || ''
                            });
                        });
                    }
                });
            }
        } catch(e) {
            log('推荐错误:' + e.toString());
        }
        VODS = d;
    `,
    
    一级: `js:
        let d = [];
        try {
            // input可能是完整URL，提取分类ID
            let cateId = input;
            if (input.indexOf('#') > -1) {
                cateId = input.split('#')[1];
            }
            
            let reqBody = JSON.stringify({
                pid: parseInt(cateId),
                page: parseInt(MY_PAGE),
                type_id: 1
            });
            let res = post(HOST + '/Pc/Resource/ModuleInfo/ShowOnes', {
                headers: {
                    'Content-Type': 'application/json'
                },
                body: reqBody
            });
            let json = JSON.parse(res);
            if (json.code === 200 && json.data && json.data.list) {
                json.data.list.forEach(module => {
                    if (module.list && Array.isArray(module.list)) {
                        module.list.forEach(it => {
                            d.push({
                                vod_id: it.vod_id + '',
                                vod_name: it.c_name || '',
                                vod_pic: it.c_pic || '',
                                vod_remarks: it.vod_continu || ''
                            });
                        });
                    }
                });
            }
        } catch(e) {
            log('一级错误:' + e.toString());
        }
        VODS = d;
    `,
    
    二级: `js:
        try {
            // input可能是完整URL，提取视频ID
            let vodId = input;
            if (input.indexOf('#') > -1) {
                vodId = input.split('#')[1];
            }
            
            let reqBody = JSON.stringify({
                vod_id: parseInt(vodId)
            });
            let res = post(HOST + '/Pc/Resource/GetVodInfo', {
                headers: {
                    'Content-Type': 'application/json'
                },
                body: reqBody
            });
            let json = JSON.parse(res);
            
            if (json.code === 200 && json.data && json.data.vodInfo) {
                let vod = json.data.vodInfo;
                
                // 获取播放列表
                let playReqBody = JSON.stringify({
                    vod_id: parseInt(vodId),
                    sort_id: 1
                });
                let playRes = post(HOST + '/Pc/Resource/GetOnePlayList', {
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: playReqBody
                });
                let playJson = JSON.parse(playRes);
                
                let playFrom = [];
                let playUrl = [];
                
                if (playJson.code === 200 && playJson.data && playJson.data.urls) {
                    playJson.data.urls.forEach(function(it) {
                        playFrom.push(it.name || 'HD');
                        playUrl.push((it.name || 'HD') + '$' + it.url);
                    });
                }
                
                VOD = {
                    vod_id: vodId,
                    vod_name: vod.vod_name || '',
                    vod_pic: vod.pic || '',
                    type_name: (vod.videoTag && vod.videoTag.join) ? vod.videoTag.join(',') : '',
                    vod_year: vod.vod_year || '',
                    vod_area: vod.vod_area || '',
                    vod_remarks: vod.vod_continu || '',
                    vod_actor: vod.vod_actor || '',
                    vod_director: vod.vod_director || '',
                    vod_content: vod.vod_use_content || '',
                    vod_play_from: playFrom.join('$$$'),
                    vod_play_url: playUrl.join('#')
                };
            }
        } catch(e) {
            log('二级错误:' + e.toString());
        }
    `,
    
    搜索: `js:
        let d = [];
        try {
            // input可能是完整URL，提取关键词
            let keyword = input;
            if (input.indexOf('#') > -1) {
                keyword = input.split('#')[1];
            }
            
            let reqBody = JSON.stringify({
                keyword: keyword,
                page: parseInt(MY_PAGE) || 1
            });
            let res = post(HOST + '/Pc/Search/WordList', {
                headers: {
                    'Content-Type': 'application/json'
                },
                body: reqBody
            });
            let json = JSON.parse(res);
            if (json.code === 200 && json.data && json.data.list) {
                json.data.list.forEach(function(it) {
                    d.push({
                        vod_id: it.vod_id + '',
                        vod_name: it.c_name || it.vod_name || '',
                        vod_pic: it.c_pic || it.vod_pic || '',
                        vod_remarks: it.vod_continu || ''
                    });
                });
            }
        } catch(e) {
            log('搜索错误:' + e.toString());
        }
        VODS = d;
    `
};
